home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Power 1998 April
/
MACPOWER-1998-04.ISO.7z
/
MACPOWER-1998-04.ISO
/
Shareware Paradise
/
Tabler.091.sit
/
Tabler 0.9.1
/
source code
/
Tabler.AE.c
< prev
next >
Wrap
Text File
|
1996-06-23
|
6KB
|
199 lines
/*
*--------------------------------------------------------------
* Tabler.AE.c
*--------------------------------------------------------------
*
* prog : rokkaku
*
*--------------------------------------------------------------
*/
#include <AppleEvents.h>
#include <Gestalt.h>
#include <Errors.h>
#include "Tabler.h"
/* number of required AppleEvents */
enum constAEHandlers {
kOpenApp = 0,
kOpenDoc,
kPrntDoc,
kQuitApp,
kNumOfAE
};
/* static functions only used in this source */
static pascal OSErr DoAEOpenApp(const AppleEvent *, AppleEvent *, long);
static pascal OSErr DoAEOpenDoc(const AppleEvent *, AppleEvent *, long);
static pascal OSErr DoAEPrintDoc(const AppleEvent *, AppleEvent *, long);
static pascal OSErr DoAEQuitApp(const AppleEvent *, AppleEvent *, long);
static OSErr GotRequiredParams(const AppleEvent *);
/* static global: AppleEvent Hander ProcPtr */
static AEEventHandlerUPP gMyAEUPPs[kNumOfAE] = { nil, nil, nil, nil };
/*
*--------------------------------------------------------------
* SetUpMyAppleEvent
*--------------------------------------------------------------
* set up Apple Event procedure
* if AppleEvent is not supported, do nothing in here
*--------------------------------------------------------------
*/
Boolean SetUpMyAppleEvent(void)
{
AEEventID anAEID;
long answer;
OSErr result;
result = Gestalt(gestaltAppleEventsAttr, &answer);
if (result != noErr || answer < gestaltAppleEventsPresent) {
result = errAEHandlerNotFound;
}
if (result == noErr) {
gMyAEUPPs[kOpenApp] = NewAEEventHandlerProc(&DoAEOpenApp);
gMyAEUPPs[kOpenDoc] = NewAEEventHandlerProc(&DoAEOpenDoc);
gMyAEUPPs[kPrntDoc] = NewAEEventHandlerProc(&DoAEPrintDoc);
gMyAEUPPs[kQuitApp] = NewAEEventHandlerProc(&DoAEQuitApp);
}
if (result == noErr) {
result = AEInstallEventHandler(kCoreEventClass, anAEID = kAEOpenApplication,
gMyAEUPPs[kOpenApp], 0, false);
}
if (result == noErr) {
result = AEInstallEventHandler(kCoreEventClass, anAEID = kAEOpenDocuments,
gMyAEUPPs[kOpenDoc], 0, false);
}
if (result == noErr) {
result = AEInstallEventHandler(kCoreEventClass, anAEID = kAEPrintDocuments,
gMyAEUPPs[kPrntDoc], 0, false);
}
if (result == noErr) {
result = AEInstallEventHandler(kCoreEventClass, anAEID = kAEQuitApplication,
gMyAEUPPs[kQuitApp], 0, false);
}
return (true);
}
/*
*--------------------------------------------------------------
* RemoveMyAppleEvent
*--------------------------------------------------------------
* delete AppleEvent handlers
*--------------------------------------------------------------
*/
void RemoveMyAppleEvent(void)
{
int i;
for (i = 0; i < kNumOfAE; ++i) {
if (gMyAEUPPs[i] != nil) {
DisposeRoutineDescriptor(gMyAEUPPs[i]);
gMyAEUPPs[i] = nil;
}
}
}
/*
*--------------------------------------------------------------
* DoAEOpenApp
*--------------------------------------------------------------
* Open Application event: do nothing
*--------------------------------------------------------------
*/
pascal OSErr DoAEOpenApp(const AppleEvent *theAE, AppleEvent *reply, long refCon)
{
#pragma unused (theAE, reply, refCon)
OSErr result = ConvertScrap();
gDone = true;
return (result);
}
/*
*--------------------------------------------------------------
* DoAEOpenDoc
*--------------------------------------------------------------
* Open Document event: do open
*--------------------------------------------------------------
*/
pascal OSErr DoAEOpenDoc(const AppleEvent *theAE, AppleEvent *reply, long refCon)
{
#pragma unused (reply, refCon)
AEDescList fileSpecList = {typeNull, nil};
FSSpec thisFileSpec;
DescType type;
AEKeyword keyword;
Size actual;
long count = 0;
long index;
OSErr result;
result = AEGetParamDesc(theAE, keyDirectObject, typeAEList, &fileSpecList);
if (result == noErr) {
result = GotRequiredParams(theAE);
}
if (result == noErr) {
result = AECountItems(&fileSpecList, &count);
}
if ((result == noErr) && (count > 0)) {
/* read only one document */
for (index = 1; index <= 1; index++) {
result = AEGetNthPtr(&fileSpecList, index, typeFSS, &keyword, &type,
(Ptr)&thisFileSpec, sizeof(FSSpec), &actual);
if (result == noErr) {
OpenSourceDoc(&thisFileSpec);
} else {
break;
}
}
}
AEDisposeDesc(&fileSpecList);
gDone = true;
return (result);
}
/*
*--------------------------------------------------------------
* DoAEPrintDoc
*--------------------------------------------------------------
* Apple Event Quit procedure
*--------------------------------------------------------------
*/
pascal OSErr DoAEPrintDoc(const AppleEvent *theAE, AppleEvent *reply, long refCon)
{
#pragma unused (theAE, reply, refCon)
return (errAEEventNotHandled);
}
/*
*--------------------------------------------------------------
* DoAEQuitApp
*--------------------------------------------------------------
* Apple Event Quit procedure
*--------------------------------------------------------------
*/
pascal OSErr DoAEQuitApp(const AppleEvent *theAE, AppleEvent *reply, long refCon)
{
#pragma unused (theAE, reply, refCon)
gDone = true;
return (noErr);
}
/*
*--------------------------------------------------------------
* GotRequiredParams
*--------------------------------------------------------------
* Apple Event requred parameter parser
*--------------------------------------------------------------
*/
static OSErr GotRequiredParams(const AppleEvent *theAE)
{
DescType returnedType;
Size actualSize;
OSErr result;
result = AEGetAttributePtr(theAE, keyMissedKeywordAttr, typeWildCard,
&returnedType, nil, 0, &actualSize );
if (result == errAEDescNotFound) {
return (noErr);
} else if (result == noErr) {
return (errAEEventNotHandled);
}
return (result);
}